<?php

namespace app\index\controller;

use think\facade\Db;
use think\facade\View;

class NewsController extends BaseController {

    public function index() {
        $newsList = Db::name('WebNews')
            ->field('id, title, img_url, `desc`, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
            ->order('create_time desc')->paginate(13);
        View::assign([
            'newsList' => $newsList,
        ]);

        return view();
    }

    public function detail() {
        $id = input('id/d', 0);
        if ($id <= 0) exit('参数错误!');
        $news = Db::name('WebNews')->where('id', $id)->field('*, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')->find();
        //p($news);

        $newsList = Db::name('WebNews')
            ->field('id, title, img_url, `desc`, DATE_FORMAT(create_time, "%Y-%m-%d") as create_time')
            ->order('sort, id desc')->paginate(13);

        View::assign([
            'news' => $news,
            'newsList' => $newsList,
        ]);
        return view();
    }
}
